rm(list=ls())
library(foreign)
library(ggplot2) 
library(gridExtra)
library(knitr)
library(grid)
library(dplyr)
library(forcats)
library(haven)
library(grid)
library(gridExtra)
library("ggtext")

theme_results <- theme_bw(base_size = 19) +
  theme(text=element_text(family="Times",
                          size = 19),
        axis.text.x = element_text(size = 19, color = "black"),
        axis.text.y = element_text(size = 15, color = "black",angle=0),
        axis.title.y = element_text(size = 19, color = "black"),
        axis.title.x = element_text(size = 17, color = "black"),
        legend.position = "bottom",
        legend.key.size = unit(1.2, "cm"),
        legend.text = element_text(size = 17),
        legend.title = element_text(size = 1),
        panel.grid.major.y = element_blank(),
        panel.grid.minor.y = element_blank(),
        panel.grid.major.x = element_blank(),
        panel.grid.minor.x = element_blank(),
        strip.background = element_rect(fill = "white"))




setwd("...")

main <- read_dta("covariate_test.dta")

covariates_plot <- main %>%
  mutate(Covariate = fct_reorder(Covariate, coef)) %>%
  ggplot(aes(x = Covariate, y = coef)) +
  geom_point(size = 1, position = position_dodge(width = 0.75)) + 
  geom_linerange(aes(ymin = ci_lower, ymax = ci_upper), position = position_dodge(width = 0.75)) +  
  geom_hline(aes(yintercept = 0), linetype = 2, color = "red") + 
  theme_bw() +
  ylab("Diff. between Treat. & Control groups") + 
  xlab("Covariate") +
  scale_y_continuous() +
  scale_x_discrete() 


  covariates_plot
  covariates_plot + coord_flip()



